package com.jlboot.model.po.sys;

import com.jlboot.core.base.Models;
import com.jfinal.plugin.activerecord.Model;
import com.jlboot.core.consts.Consts;
import com.jlboot.core.util.LoginUtil;

import java.util.Date;
import java.util.List;

/**
 * Created by 51594 on 2022/9/10.
 */
public class SysRole extends Model<SysRole> {
    public static final SysRole dao = new SysRole().dao();
    public static final String table="sys_role";
    public Models mod = Models.n(this);

    public static String getNextId(){
        return SysIdGenerator.dao.getNextId(table);
    }

    public SysRole setCommon(){
        Date now=new Date();
        this.set("id",SysIdGenerator.dao.getNextId(table));
        this.set("del_tag", Consts.COMMON_NONE_DEL);
        this.set("create_time",now);
        this.set("update_time",now);
        this.set("create_by", LoginUtil.getUserId());
        this.set("update_by",LoginUtil.getUserId());
        return this;
    }


    public List<SysRole> getUserRoleList(Object userId){
        String sql="select b.* from sys_user_role a" +
                " left join sys_role b on a.role_id=b.id " +
                " where a.del_tag=0 and a.user_id=?";
        return find(sql,userId);
    }

}
